package com.zdemo.hash2;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class Tester {
	
	public static void main(String[] args) {
		final ExecutorService exec = Executors.newFixedThreadPool(50);
		final HashHandler handler = new HashHandler();
		for(int i = 0; i < 10000; i++) {
			Runnable r = new Runnable() {
				@Override
				public void run() {
					sleep();
					int random = (int) (Math.random() * 100000 + 1);
					sleep();
					Integer hashCode = handler.getHash(random);
					if((random * 2) != hashCode.intValue()) {
						System.out.println(random * 2 + "," + hashCode);
					} 
				}
			};
			exec.submit(r);
		}
		
		exec.shutdown();

		while (true) {
			if (exec.isTerminated()) {
				System.out.println("finished!");
				break;
			}
		}
	}
	
	private static void sleep() {
		try {
			Thread.sleep((long) (Math.random() * 10 + 1));
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
